/*
** check.c for colle in /home/deubel_j//colle
** 
** Made by james deubelbeiss
** Login   <deubel_j@epitech.net>
** 
** Started on  Mon Apr 18 22:42:03 2011 james deubelbeiss
** Last update Mon Apr 18 22:43:47 2011 james deubelbeiss
*/

#include "my_mastermind.h"

int	my_check_args(t_args *args)
{
  if (args->slots <= 0)
    my_puterr("Number of slots must be > 0\n");
  else if (my_strlen(args->code) != args->slots)
    my_puterr("Secret code is too long/short, use option -s [SLOTS]\n");
  else if (!my_check_str_base(args->code, args->pions))
    my_puterr("Secret code contains unknown pion(s)\n");
  else if (!my_check_doublon(args->pions))
    my_puterr("Pion list contains doublons\n");
  else if (args->tentatives <= 0)
    my_puterr("Number of tentatives must be > 0\n");
  else
    return (1);
  return (0);
}

int	my_check_str_base(char *str, char *base)
{
  int	i;
  int	j;

  i = 0;
  while (str[i])
    {
      j = 0;
      while (base[j] && str[i] != base[j])
	j++;
      if (!base[j])
	return (0);
      i++;
    }
  return (1);
}

int	my_check_doublon(char *str)
{
  int	i;
  int	j;

  i = 0;
  while (str[i])
    {
      j = 0;
      while (str[j])
	{
	  if (str[i] == str[j] && i != j)
	    return (0);
	  j++;
	}
      i++;
    }
  return (1);
}
